package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.config.CommonResult;
import com.neuedu.yyzx.entity.CustomerInformation;
import com.neuedu.yyzx.service.ICustomerInformationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第7组....
 * @since 2021-04-28
 */
@RestController
@RequestMapping("//customerInformation")
public class CustomerInformationController {

    @Autowired
    ICustomerInformationService customerInformationService;

    @RequestMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNo , @RequestParam(defaultValue = "10") Integer pageSize, CustomerInformation customerInformation){

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",0);
        if(customerInformation!=null && StringUtils.isNotEmpty(customerInformation.getName())){
            queryWrapper.like("name",customerInformation.getName());
        }

        return CommonResult.success(customerInformationService.page(new Page<>(pageNo,pageSize),queryWrapper));

    }

    @RequestMapping("/toAdd")
    CommonResult toAdd(CustomerInformation customerInformation){
        return CommonResult.success(customerInformationService.saveOrUpdate(customerInformation));
    }

    @RequestMapping("/update")
    CommonResult update(Integer id){
        return CommonResult.success(customerInformationService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult deleteById(Integer id) {
        return CommonResult.success((customerInformationService.removeById(id)));
    }
}
